import { testCart, testCpu, testCpuBus, testPPU } from "./test";

// 测试下数据
const input = document.getElementById("file-input") as HTMLInputElement
const nextBtn = document.getElementById("next") as HTMLButtonElement;

input?.addEventListener("change", () => {
    input.disabled = true;
    // 读取文件
    const reader = new FileReader();
    const file = (input as any).files[0];
    let buffer = new Uint8Array(0)

    reader.readAsArrayBuffer(file);
    reader.onload = e => {
        // 多次加载
        let data = new Uint8Array(e.target?.result as ArrayBuffer)
        const tmp = new Uint8Array(buffer.length + data.length);
        tmp.set(buffer);
        tmp.set(data, buffer.length)

        buffer = tmp;
    }

    reader.onloadend = () => {
        // 测试
        // testCart(buffer)
        // testCpuBus(buffer);
        // let cpu = testCpu(buffer)
        // nextBtn.onclick = () => {
        //     cpu.clock();
        // }
        testPPU(buffer);
        
    }
})

